using Moq;
using NUnit.Framework;
using Tycho.Parser.Peg;

namespace Tycho.Parser.Tests.Peg {
    [TestFixture]
    public class InfixCompositeTermSpecification {
        [Test]
        public void FirstShouldGetSetSubTermWithNameSetForFirst () {
            var term = new InfixCompositeTerm ("name", new Mock<IPrecedence> ().Object, "first", "last", null);

            var first = new IntegerTerm (0, null);
            term.First = first;
            Assert.That (term.SubTerms["first"], Is.SameAs (first));
            Assert.That (term.First, Is.SameAs (first));
        }

        [Test]
        public void LastShouldGetSetSubTermWithNameSetForLast () {
            var term = new InfixCompositeTerm ("name", new Mock<IPrecedence> ().Object, "first", "last", null);

            var last = new IntegerTerm (0, null);
            term.Last = last;
            Assert.That (term.SubTerms["last"], Is.SameAs (last));
            Assert.That (term.Last, Is.SameAs (last));
        }

        [Test]
        public void PrecedenceShouldBeValueGivenAsPrecedence () {
            var precedence = new Mock<IPrecedence> ().Object;
            var term = new InfixCompositeTerm ("name", precedence, "first", "last", null);

            Assert.That (term.Precedence, Is.EqualTo (precedence));
        }
    }
}